package com.ruoyi.web.controller.bus.controller;

import com.ruoyi.bus.domain.BusMonitor;
import com.ruoyi.bus.service.IBusMonitorService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-08-31
 */
@Controller
@RequestMapping("/api/monitor")
@CrossOrigin
public class ApiMonitorController extends BaseController
{
    private String prefix = "bus/monitor";

    @Autowired
    private IBusMonitorService busMonitorService;

    @RequiresPermissions("bus:monitor:view")
    @GetMapping()
    public String monitor()
    {
        return prefix + "/monitor";
    }


    @RequestMapping("/apiList")
    @ResponseBody
    public Result apiList(BusMonitor busMonitor) {
        List<BusMonitor> list = busMonitorService.selectBusMonitorList(busMonitor);
        Map map = new HashMap();
        map.put("list",list);
        return new Result(true,200,"查询成功",map);
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("bus:monitor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusMonitor busMonitor)
    {
        startPage();
        List<BusMonitor> list = busMonitorService.selectBusMonitorList(busMonitor);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("bus:monitor:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusMonitor busMonitor)
    {
        List<BusMonitor> list = busMonitorService.selectBusMonitorList(busMonitor);
        ExcelUtil<BusMonitor> util = new ExcelUtil<BusMonitor>(BusMonitor.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("bus:monitor:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusMonitor busMonitor)
    {
        return toAjax(busMonitorService.insertBusMonitor(busMonitor));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{monitorId}")
    public String edit(@PathVariable("monitorId") Long monitorId, ModelMap mmap)
    {
        BusMonitor busMonitor = busMonitorService.selectBusMonitorByMonitorId(monitorId);
        mmap.put("busMonitor", busMonitor);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("bus:monitor:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusMonitor busMonitor)
    {
        return toAjax(busMonitorService.updateBusMonitor(busMonitor));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("bus:monitor:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busMonitorService.deleteBusMonitorByMonitorIds(ids));
    }
}
